package com.pxene.dmp.common;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class URLUtils {

	public static String regexpExtract(String str, String regex) {
		if (str == null || regex == null) {
			return "";
		}
		Pattern REGEX_PATTERN = Pattern.compile(regex);
		Matcher matcher = REGEX_PATTERN.matcher(str);
		if (matcher.find()) {
			return matcher.group(1);
		}
		return "";
	}

	public static Map<String, String> getQueryMap(String str) {
		Map<String, String> map = new HashMap<String, String>();
		if (str == null) {
			return map;
		}
		String[] querys = str.split("&");
		for (String query : querys) {
			int pos = query.indexOf("=");
			if (pos != -1 && pos != 0 && pos != query.length()) {
				map.put(query.substring(0, pos), query.substring(pos + 1, query.length()));
			}
		}
		return map;
	}

	public static String removePunctuations(String str) {
		if (str == null) {
			return "";
		}
		return str.replaceAll("[\\pP\\pZ\\pS]", "");
	}

}
